75B - Facetook Priority Wall - CodeForces Solution


expression parsing implementation strings *1500

Please click on ads to support us..

Python Code:

import operator
from collections import OrderedDict
my=input()
value={}
for i in range(int(input())):
	s=input()
	if("posted on" in s):
		a1=s[0:s.find(" posted on")]
		a2=s[s.find("posted on")+10:-7]
		f=3
	elif("commented on" in s):
		a1=s[0:s.find(" commented on")]
		a2=s[s.find("commented on")+13:-7]
		f=2
	else:
		a1=s[0:s.find(" likes ")]
		a2=s[s.find(" likes ")+7:-7]
		f=1
	if(a1==my  or a2==my):
		if(a1 in value):
			value[a1]+=5*f
		else:
			value[a1]=5*f
		if(a2 in value):
			value[a2]+=5*f
		else:
			value[a2]=5*f
	else:
		if(a1 not in value):
			value[a1]=0
		if(a2 not in value):
			value[a2]=0
	value=OrderedDict(sorted(value.items()))
sorted_value=dict(sorted(value.items(),key=operator.itemgetter(1),reverse=True))
for key in sorted_value:
	if(key!=my):
		print(key)

C++ Code:

#include <iostream>
#include <string>
#include<iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <numeric>
#include<unordered_map>
#include <unordered_set>
#include <cmath>
#include<vector>
#include<algorithm>
#define ll long long
#define endl "\n"
#define GG  ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;
bool ok(ll mid, ll k) {
	return true;
}
ll bs(ll k) {
	ll l = 0, r = 1e10, sum = 0;
	while (l <= r) {
		ll mid = l + (r - l) / 2;
		if (ok(mid, k)) {
			sum = mid;
			l = mid + 1;
		}
		else {
			r = mid - 1;
		}
	}
	return sum;
}
ll gcd(ll n, ll m) {
	if (n == 0 || m == 0) {
		return max(n, m);
	}
	if (n == m) {
		return n;
	}
	return gcd(n % m, m % n);
}
ll lcm(ll n, ll m) {
	return (n / gcd(n, m)) * m;
}
ll fastpower(ll b, ll p) {
	ll halfpower = fastpower(b, p / 2);
	ll res = halfpower * halfpower;
	if (p % 2 != 0) {
		res *= b;
	}
	return res;
}
bool wp(const pair<int, string>& a, const pair<int, string>& b)
{
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return (a.first > b.first);
}
int main() {
	//freopen("hobz.in", "r", stdin);
	//freopen("Round1.in", "r", stdin);
	//freopen("hanya.in", "r", stdin);
	//freopen("tabs.in", "r", stdin);
	GG;
	string s;
	cin >> s;
	ll t;
	cin >> t;
	map<string, ll>mp;
	while (t--) {
		string s1, s2, s3, s4, s5, a = "";
		cin >> s1 >> s2;
		if (s2 == "posted" || s2 == "commented") {
			cin >> s3;
		}
		cin >> s4 >> s5;
		s4.pop_back();
		s4.pop_back();
		a = s4;
		if (s1 == s || a == s) {
			if (s2 == "posted") {
				mp[s1] += 15;
				mp[a] += 15;
			}
			else if (s2 == "commented") {
				mp[s1] += 10;
				mp[a] += 10;
			}
			else if (s2 == "likes") {
				mp[s1] += 5;
				mp[a] += 5;
			}
		}
		mp[s1] += 0;
		mp[a] += 0;
	}
	vector<pair<ll, string>>v;
	for (auto i : mp) {
		if (i.first != s) {
			v.push_back({ i.second,i.first });
		}
	}
	sort(v.begin(), v.end(), wp);
	for (auto i : v) {
		cout << i.second << endl;
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers